import { createRouter, createWebHistory } from 'vue-router'
import dlRoute from './dlRoute'
import dmhRoute from './dmhRoute'
import hfRoute from "./hfRoute"
import hxRoute from './hxRoute'
import zxlRoute from './zxlRoute'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "/Home"
    },
    {
      path: "/Login",
      name: "Login",
      component: () => import("@/views/Login.vue"),
      meta: {
        required: true
      }
    },
    {
      path: '/Home',
      name: 'Home',
      redirect: "/Home/bodyTest",
      component: () => import("@/views/Index.vue"),
      children: [
        ...dlRoute, ...dmhRoute, ...hfRoute, ...hxRoute, ...zxlRoute
      ]
    }
  ]
})

router.beforeEach((to, _, next) => {
  if (!to.meta.required) {
    if (!sessionStorage.getItem("token")) {
      next("/Login")
    }
  }
  next()
})


export default router
